package org.ariadne_eu.hcifetcher.mumeUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.ariadne_eu.hcifetcher.rest.RestUtils;
import org.json.JSONException;
import org.json.JSONObject;

@Path("/entries/todo")
public class Todoitem {

	
	@Path("/")
	@GET
	@Produces("application/json")
	public String getTodoItemsOfStudent(@QueryParam("studentid") String name, @QueryParam("offset") String offset, @QueryParam("size")String size) {
		int intoffset = 0, intsize = 1000;
		try{
			intoffset = Integer.parseInt(offset);
			intsize = Integer.parseInt(size);
		}catch (Exception e) {//can't parse, use default values
		}
		Map<String, Object> filter = new HashMap<String, Object>();
		filter.put("studentid", name);
		return RestUtils.getInstance().JSONToString(RestUtils.getInstance().getEntriesJSON("TodoItem", filter, intoffset, intsize, "datestamp", false));
	}
	@Path("/todolist")
	@GET
	@Produces("application/json")
	public String getItemsonTodoOfStudent(@QueryParam("studentid") String studentid, @QueryParam("offset") String offset, @QueryParam("size") String size){
		int intoffset = 0, intsize = 50;
		try{
			intoffset = Integer.parseInt(offset);
			intsize = Integer.parseInt(size);
		}catch (Exception e) {//can't parse, use default values
		}
		Map<String, Object> filter = new HashMap<String, Object>();
		filter.put("studentid", studentid);
		Vector<JSONObject> todoitems = RestUtils.getInstance().getEntriesJSON("TodoItem", filter, intoffset, intsize, "datestamp", false);
		Vector<JSONObject> items = new Vector<JSONObject>();
		for(JSONObject todoitem : todoitems){
			try {
				items.add(RestUtils.getInstance().getEntityById(todoitem.getString("itemid")));
			} catch (JSONException e) {	}
		}
		return RestUtils.getInstance().JSONToString(items);
	}
}
